#
#.SYNOPSIS
#	QMLWriter.ps is a library file with the purpose to be dot sourced
#	Author: Roel Bindels
#
#.DESCRIPTION
#    
#
#	Tested on: PowerShell ISE V2.
#

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLAnswerType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,
    		[parameter(Mandatory=$false)]
            [ValidateSet("Y", "N", "YES", "NO")]
            [String[]]
            $a_strComment,
   			[parameter(Mandatory=$false)]
            [ValidateRange(1,40)]
            [Int]
            $a_nCommentHeight,
            [parameter(Mandatory=$false)]
            [ValidateLength(0,1024)]
            [String[]]
            $a_strCommentLabel,            
            [parameter(Mandatory=$false)]
            [ValidateRange(5,100)]
            [Int]
            $a_nCommentWidth,
			[parameter(Mandatory=$false)]
            [ValidateRange(0,40)]
            [Int]
            $a_nMaxSelect,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strQuestionType, 
            [parameter(Mandatory=$false)]
            [ValidateSet("N", "NO", "Y", "YES", "P", "PART", "T", "EXCEPT_LAST_TWO", "n", "no", "y", "yes", "p", "part", "t", "except_last_two")]
            [String[]]
            $a_strShuffle,    
            [parameter(Mandatory=$false)]
            [ValidateSet("VERT", "HORZ", "FLASH")]
            [String[]]
            $a_strSubType)
	
	$element=$doc.CreateElement("ANSWER")
	
	#$element.Set_InnerText($value1)
	if($a_strComment)      {$element.SetAttribute("COMMENT",$a_strComment)}
	if($a_nCommentHeight)  {$element.SetAttribute("COMMENTHEIGHT",$a_nCommentHeight)}
	if($a_strCommentLabel) {$element.SetAttribute("COMMENTLABEL",$a_strCommentLabel)}
	if($a_nCommentWidth)   {$element.SetAttribute("COMMENTWIDTH",$a_nCommentWidth)}
	if($a_nMaxSelect)      {$element.SetAttribute("MAXSELECT",$a_nMaxSelect)}
	if($a_strQuestionType) {$element.SetAttribute("QTYPE",$a_strQuestionType)}
	if($a_strShuffle)      {$element.SetAttribute("SHUFFLE",$a_strShuffle)}
	if($a_strSubType)      {$element.SetAttribute("SUBTYPE",$a_strSubType)}
	
		
	[void]$parent.AppendChild($element)
	return $element
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLChoiceType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strId,
            [parameter(Mandatory=$false)]
            [ValidateRange(0,32767)]
            [Int]
            $a_nMaxChars,
            [parameter(Mandatory=$false)]
            [ValidateSet("VERT", "HORZ", "FLASH")]
            [String[]]
            $a_strScroll
            )
	 
	$element=$doc.CreateElement("CHOICE")
	
	#$element.Set_InnerText($value1)
	if($a_strId)		{$element.SetAttribute("ID",$a_strId)}
	if($a_nMaxChars)	{$element.SetAttribute("MAXCHARS",$a_nMaxChars)}
	if($a_strScroll)	{$element.SetAttribute("SCROLL",$a_strScroll)}
		
	[void]$parent.AppendChild($element)
	return $element
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLCommentType{
    param( [parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,
    		[parameter(Mandatory=$false)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strComment,
     		[parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strAuthor,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strDate,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strName,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strType
            )
	 
	$element=$doc.CreateElement("COMMENT")
	
	$element.Set_InnerText($a_strComment)
	if($a_strAuthor)	{$element.SetAttribute("AUTHOR",$a_strAuthor)}
	if($a_strDate)		{$element.SetAttribute("DATE",$a_strDate)}
	if($a_strName)		{$element.SetAttribute("NAME",$a_strName)}
	if($a_strType)		{$element.SetAttribute("TYPE",$a_strType)}
		
	[void]$parent.AppendChild($element)
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLContentType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,
    		[parameter(Mandatory=$true)]
            [String[]]
            $a_strContent,            
    		[parameter(Mandatory=$false)]
            [ValidateSet("Left", "Right", "Top", "Bottom", "Middle")]
            [String[]]
            $a_strAlign,
            [parameter(Mandatory=$false)]
            [ValidateLength(0,100)]
            [String[]]
            $a_strAlt,
            [parameter(Mandatory=$false)]
            [ValidateSet("FALSE", "TRUE")]
            [String[]]
            $a_strAutostart,
            [parameter(Mandatory=$false)]
            [ValidateRange(0,50)]
            [Int]
            $a_nBorder,
            [parameter(Mandatory=$false)]
            [ValidateRange(0,32767)]
            [Int]
            $a_nHeigth,
            [parameter(Mandatory=$false)]
            [ValidateSet("FALSE", "TRUE")]
            [String[]]
            $a_strHidden,
            [parameter(Mandatory=$false)]
            [ValidateRange(0,50)]
            [Int]
            $a_nHSpace,
            [parameter(Mandatory=$false)]
            [ValidateSet("FALSE", "TRUE")]
            [String[]]
            $a_strLoop,
            [parameter(Mandatory=$false)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strName,
            [parameter(Mandatory=$false)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strStyle,
            [parameter(Mandatory=$false)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strType = "text/html",
            [parameter(Mandatory=$false)]
            [ValidateRange(0,50)]
            [Int]
            $a_nVSpace,
            [parameter(Mandatory=$false)]
            [ValidateRange(0,32767)]
            [Int]
            $a_nWidth
            )
	  
	$element=$doc.CreateElement("CONTENT")
	
    $cdata = $doc.CreateCDataSection($a_strContent)
    [void]$element.AppendChild($cdata)
    
	#$element.Set_InnerText($a_strContent)
	if($a_strAlign)		{$element.SetAttribute("ALIGN",$a_strAlign)}
	if($a_strAlt)		{$element.SetAttribute("ALT",$a_strAlt)}
	if($a_strAutostart)	{$element.SetAttribute("AUTOSTART",$a_strAutostart)}
	if($a_nBorder)		{$element.SetAttribute("BORDER",$a_nBorder)}
	if($a_nHeigth)		{$element.SetAttribute("HEIGTH",$a_nHeigth)}
	if($a_strHidden)		{$element.SetAttribute("HIDDEN",$a_strHidden)}
	if($a_nHSpace)		{$element.SetAttribute("HSPACE",$a_nHSpace)}
	if($a_strLoop)		{$element.SetAttribute("LOOP",$a_strLoop)}
	if($a_strName)		{$element.SetAttribute("NAME",$a_strName)}
	if($a_strStyle)		{$element.SetAttribute("STYLE",$a_strStyle)}
	if($a_strType)		{$element.SetAttribute("TYPE",$a_strType)}
	if($a_nVSpace)		{$element.SetAttribute("VSPACE",$a_nVSpace)}
	if($a_nWidth)		{$element.SetAttribute("WIDTH",$a_nWidth)}
	
		
	[void]$parent.AppendChild($element)
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLOutcomeType{
    param([parameter(Mandatory=$true)]
    		$doc,
    		[parameter(Mandatory=$true)]
    		$parent,
            [parameter(Mandatory=$false)]
            [Int]
            $a_nAdd,
            [parameter(Mandatory=$false)]
            [ValidateSet("FALSE", "TRUE")]
            [String[]]
            $a_strContinue,
            [parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strId,
            [parameter(Mandatory=$false)]
            [Int]
            $a_nScore
            )
	  
	$element=$doc.CreateElement("OUTCOME")
	
	#$element.Set_InnerText($value1)
	if($a_nAdd)			{$element.SetAttribute("ADD",$a_nAdd)}
	if($a_strContinue)	{$element.SetAttribute("CONTINUE",$a_strContinue)}
	if($a_strId)		{$element.SetAttribute("ID",$a_strId)}
	$element.SetAttribute("SCORE",$a_nScore)
		
	[void]$parent.AppendChild($element)
    return $element
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLTagType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,  		            
    		[parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strName,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strTag)
    #Write-Host
	  
	$element=$doc.CreateElement("TAG")
	
	$element.Set_InnerText($a_strTag)
	if($a_strName)	{$element.SetAttribute("NAME",$a_strName)}
		
	[void]$parent.AppendChild($element)
}


#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLConditionType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,  		            
    		[parameter(Mandatory=$true)]
            [ValidateLength(0,50)]
            [String[]]
            $a_strCondition
            )
	  
	$element=$doc.CreateElement("CONDITION")
	
	$element.Set_InnerText($a_strCondition)
		
	[void]$parent.AppendChild($element)
}

#
#.SYNOPSIS
#
#
#.DESCRIPTION
#    
#
#----------------------------------------
function createQMLQuestionType{
    param([parameter(Mandatory=$true)]
    		$doc,
            [parameter(Mandatory=$true)]
    		$parent,  		            
    		[parameter(Mandatory=$true)]
            [ValidateLength(0,16)]
            [String[]]
            $a_strId,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strTopic,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strDescription,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strType,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strStatus,
            [parameter(Mandatory=$false)]            
            [Int]
            $a_nCeiling,
            [parameter(Mandatory=$false)]            
            [Int]
            $a_nFloor,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strVoiceServer,
            [parameter(Mandatory=$false)]            
            [String[]]
            $a_strVoiceRid
            )
	
	$element=$doc.CreateElement("QUESTION")
	
	$element.Set_InnerText($a_strTag)
	if($a_strId)			{$element.SetAttribute("ID",$a_strId)}
	if($a_strTopic)			{$element.SetAttribute("TOPIC",$a_strTopic)}
	if($a_strDescription)	{$element.SetAttribute("DESCRIPTION",$a_strDescription)}
	if($a_strType)			{$element.SetAttribute("TYPE",$a_strType)}
	if($a_strStatus)		{$element.SetAttribute("STATUS",$a_strStatus)}
	if($a_nCeiling)			{$element.SetAttribute("CEILING",$a_nCeiling)}
	if($a_nFloor)			{$element.SetAttribute("FLOOR",$a_nFloor)}
	if($a_strVoiceServer)	{$element.SetAttribute("VOICE_SERVER",$a_strVoiceServer)}
	if($a_strVoiceRid)		{$element.SetAttribute("VOICE_RID",$a_strVoiceRid)}
		
	[void]$parent.AppendChild($element)
    return $element    
}


